package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.CarfromOneAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.utils.DataUtils;
import com.bjesc_b2c.app.appraiset.widget.dialog.DateTimeDialog;
import com.bjesc_b2c.app.appraiset.widget.dialog.DefeatCauseDialog;
import com.bjesc_b2c.app.appraiset.widget.dialog.InputPriceDialog;

import java.util.Date;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;
import butterknife.Bind;
import butterknife.OnClick;
import master_bean.CarForBean;

/**
 * Created by yidong on 2017/5/26.
 */

public class SelectTypeActivity extends BaseActivity implements MultiItemTypeAdapter.OnItemClickListener,
        DateTimeDialog.MyOnDateSetListener,DefeatCauseDialog.OnSelectListener,InputPriceDialog.InputPriceListener{
    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;
    @Bind(R.id.tv_title)
    TextView title;
    private CarfromOneAdapter adapter;
    private List<CarForBean> typeList;
    private LinearLayoutManager manager;
    private int sType;
    private String status;
    private String typeName;
    private String typeId;

    @Override
    protected int getLayout() {
        return R.layout.activity_car_from;
    }

    @Override
    protected void initEventAndData() {
        sType = getIntent().getIntExtra("SelecType", 1);
        if (sType == 1) {
            title.setText("价格选择");
            typeList = DataUtils.getPriceList(this);
        } else if (sType == 3) {
            title.setText("等级");
            typeList = DataUtils.getGradeTypeList(this);
        }else if(sType == 4){
            title.setText("需求购车时间");
            typeList = DataUtils.getBuyCarTimeList(this);
        }else if(sType == 5){
            title.setText("变速箱");
            typeList = DataUtils.getCarGearboxList(this);
        }
        adapter = new CarfromOneAdapter(this, R.layout.layout_item_carfrom_one, typeList,2);
        manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
    }

    @Override
    protected void createPresenter() {

    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        Intent intent = new Intent();
        intent.putExtra("typeName", typeList.get(position).getName());
        intent.putExtra("typeId", typeList.get(position).getId());
        if (sType == 1) {
            setResult(RequestAndResultCode.BIGCARSOURCEPHOTOACTIVITY_BACK_CARENGINEFRAGMENT_RESULT, intent);
            finish();
        }
        if (sType == 2) {
            typeId = typeList.get(position).getId();
            typeName = typeList.get(position).getName();
            switch (position){
                case 0://未见面
                    DateTimeDialog dateTimeDialog = new DateTimeDialog(this, null, this);
                    dateTimeDialog.hideOrShow();
                    break;
                case 1://见面未成交
                    DateTimeDialog dateTime = new DateTimeDialog(this, null, this);
                    dateTime.hideOrShow();
                    break;
                case 2://博精成交
                    InputPriceDialog priceDialog = new InputPriceDialog(SelectTypeActivity.this,this);
                    priceDialog.show();
                    break;
                case 3://战败
                    DefeatCauseDialog dialog = new DefeatCauseDialog(SelectTypeActivity.this,this);
                    dialog.show();
                    break;
            }
        }

        if (sType == 3) {
            setResult(RequestAndResultCode.CarModelActivity_Result, intent);
            finish();
        }
        if (sType == 4) {
            setResult(RequestAndResultCode.CAROFFSHELFACTIVITY_BACK_RESULT, intent);
            finish();
        }
        if (sType == 5) {
            setResult(RequestAndResultCode.CarSeriesAcitivty_TO_CarModelActivity, intent);
            finish();
        }
    }

    @Override
    public void onDateSet(Date date) {
        Intent intent  =  new Intent();
        intent.putExtra("typeId",typeId);
        intent.putExtra("date",date);
        intent.putExtra("typeName", typeName);
        setResult(RequestAndResultCode.BIGCARSOURCEPHOTOACTIVITY_BACK_CARENGINEFRAGMENT_RESULT,intent);
        finish();
    }

    @Override
    public void onSelect(String soldType, String remarks) {
        Intent intent  =  new Intent();
        intent.putExtra("typeId",typeId);
        intent.putExtra("typeName", typeName);
        intent.putExtra("soldType",soldType);
        intent.putExtra("soldRemarks",remarks);
        setResult(RequestAndResultCode.BIGCARSOURCEPHOTOACTIVITY_BACK_CARENGINEFRAGMENT_RESULT,intent);
        finish();
    }

    @Override
    public void priceCallBack(String price) {

    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    @OnClick(R.id.iv_return)
    public void onClick() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
